package io.netty.example.http.helloworld;

import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.net.Socket;

public class TestHttpServer {
	public static void testSocket(){
		String phpSessID = "test";
		try {
			String paramStr = "params=ddddd";
			
			Socket socket = new Socket("localhost", 8080);
			
			// Send header
			String crlf = "\r\n";
			String path = "/php/0/0/0/abc.test";
			BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), "UTF-8"));
			wr.write("POST " + path + " HTTP/1.1" + crlf);
			wr.write("Host: localhost:8080" + crlf);
			wr.write("Connection: keep-alive" + crlf);
			wr.write("Cookie: PHPSESSID=" + phpSessID + crlf);
			wr.write("Content-Length: " + paramStr.getBytes().length + crlf);
			wr.write("Content-Type: application/x-www-form-urlencoded" + crlf);
			wr.write(crlf);
			wr.write(paramStr);
			wr.flush();
			
			socket.close();
			
		} catch (Exception e) {
			e.printStackTrace();
		}		
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		testSocket();

	}

}
